public class test1 {
    //力扣:1089. 复写零
    public static void duplicateZeros(int[] arr) {
        //双指针(注意边界)
        int dest=-1;
        int cur=0;
        while(cur<arr.length){
            if(arr[cur]==0){
                dest+=2;
            }else{
                dest++;
            }
            if(dest>=arr.length-1)break;
            cur++;
        }
        if(dest==arr.length){
            arr[--dest]=0;
            dest--;
            cur--;
        }
        while(cur>=0){
            if(arr[cur]==0){
                arr[dest--]=0;
                arr[dest]=0;
            }else{
                arr[dest]=arr[cur];
            }
            cur--;
            dest--;
        }
    }

    public static void main(String[] args) {
        int[]arr={0,1,7,6,0,2,0,7};
        duplicateZeros(arr);
    }
}
